﻿@{
    ViewBag.Title = "学生所修课程管理";
    Layout = "~/Views/Shared/_GridCommonLayout.cshtml";
}



<!--begin grid code-->


<section id="widget-grid" class="">
    <div class="row">




        <!--Operation-->
        <div class="heading-buttons">


            <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                <h1 class="page-title txt-color-blueDark"><i class="fa fa-bell "></i>
                    学生所修课程管理
			
                </h1>
            </div>
            <div class="buttons pull-right">

                <button type="button" class="btn btn-success btn-labeled "
                    data-bind="click: $root.showAddBefore">
                    <span class="btn-label"><i class="glyphicon glyphicon-plus"></i>
                    </span>添加记录</button>

                <button type="button" class="btn btn-primary btn-labeled "
                    data-bind="click: $root.onDataDeleting">
                    <span class="btn-label"><i class="glyphicon glyphicon-remove"></i>
                    </span>批量删除</button>


            </div>
            <div style="clear: both;">
            </div>
        </div>
        <!--/Operation-->




        <!--Search-->
        <div class="filter-bar">
            <form id="formSearch">
                <div class="lbl glyphicons search" style="cursor: pointer;" data-bind="click: $root.search">
                    <i></i>筛选
                </div>

                <div>
                    <label>学生学号：</label><div class='input-append'>
                        <input id='txtbSrSStuNo' name='txtbSrSStuNo' type='text' placeholder='学生学号' class='input-mini' style='width: 120px;' />
                    </div>
                </div>
                <div>
                    <label>课程名：</label><div class='input-append'>
                        <input id='txtbSrSCourseName' name='txtbSrSCourseName' type='text' placeholder='课程名' class='input-mini' style='width: 120px;' />
                    </div>
                </div>
                <div>
                    <label>教师工号：</label><div class='input-append'>
                        <input id='txtbSrSTeacherCode' name='txtbSrSTeacherCode' type='text' placeholder='教师工号' class='input-mini' style='width: 120px;' />
                    </div>
                </div>
                <div>
                    <label>学年学期名：</label>
                    @Html.DropDownList("txtbSrSTermName", new SelectList(ViewBag.termList, "STermName", "STermName"), "--请选择--", new { @style = "width: 120px;border:1px solid #cccccc" })
                </div>





                <div class="clearfix">
                </div>
            </form>
        </div>
        <!--/search-->



        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
            <div id="wid-id-0" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-editbutton="false">
                <header>
                    <span class="widget-icon"><i class="fa fa-table"></i></span>
                    <h2>学生所修课程</h2>
                </header>
                <div style="margin-top: 35px;">
                    <div class="jarviswidget-editbox"></div>
                    <div class="widget-body no-padding">
                        <div role="grid" id="providerGrid" class="dataTables_wrapper form-inline">
                            <div class="table-responsive">

                                <div class="dt-wrapper" style="overflow-y: auto;">
                                    <table class="table table-striped table-bordered table-hover checkboxs">
                                        <!--table head-->
                                        <thead>
                                            <tr>
                                                <th style="width: 1%">
                                                    <input type="checkbox" value="0" />
                                                </th>
                                                <!-- ko foreach: headers -->
                                                <th class="center ">
                                                    <a href="#" data-bind="text: displayText@*, click: $root.sort*@" style="color: black"></a>
                                                    <i class="icon-circle-arrow-up" data-bind="    visible: value == $root.orderBy() && $root.isAsc()"></i>
                                                    <i class="icon-circle-arrow-down" data-bind="    visible: value == $root.orderBy() && !$root.isAsc()"></i>
                                                </th>
                                                <!-- /ko -->
                                                <th class="center" style="width: 60px">操作
                                                </th>
                                            </tr>
                                        </thead>
                                        <!--/table head-->
                                        <!--table body(Provider list)-->
                                        <tbody data-bind="foreach: recordSet">
                                            <tr class="selectable" onclick="">
                                                <td class="center">
                                                    <input type="checkbox" name="userSelector" data-bind="value: Id" />
                                                    <input type="hidden" data-bind="value: Id, attr: { id: Id }" />
                                                </td>
                                                <td class='center'><strong data-bind='text: Id'></strong></td>
                                                <td class='center'><strong data-bind='text: SStuNo'></strong></td>
                                                <td class='center'><strong data-bind='text: SStuName'></strong></td>
                                                <td class='center'><strong data-bind='text: sex(ISex)'></strong></td>
                                                <td class='center'><strong data-bind='text: SCourseName'></strong></td>
                                                <td class='center'><strong data-bind='text: SCouseCode'></strong></td>
                                                <td class='center'><strong data-bind='text: STeacherCode'></strong></td>
                                                <td class='center'><strong data-bind='text: STeacherName'></strong></td>
                                                <td class='center'><strong data-bind='text: STermName'></strong></td>


                                                <td class="center">
                                                    <a href="#" class="btn-action glyphicons pencil btn-success" data-bind="click: $root.showUpdateModal">
                                                        <i></i></a>
                                                </td>
                                            </tr>
                                        </tbody>
                                        <!--/table body( Provider list)-->

                                    </table>

                                </div>



                                <!-- 分页 -->
                                <ul class="pagination pagination-alt">
                                    <li>
                                        <a data-bind="click: firstPage"><i class="fa fa-fast-backward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: prevPage"><i class="fa  fa-backward  "></i></a>
                                    </li>
                                    <li>
                                        <a>
                                            <input id="toPage" type="text" data-bind="value: pageIndex, event: { change: $root.changePageIndex }" style="width: 25px;" />
                                            /共<span data-bind="html: totalPages"></span>页 
                                        </a>
                                    </li>
                                    <li>
                                        <a data-bind="click: nextPage"><i class="fa fa-forward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: lastPage"><i class="fa fa-fast-forward "></i></a>
                                    </li>
                                </ul>

                                <div class="dt-top-row total  ">
                                    当前记录共：<span data-bind="html: totalCount"></span>条
                                </div>
                                <!--end 分页-->
                            </div>

                            <!-- /分页 -->


                        </div>

                        <!-- /分页 -->




                    </div>
                </div>

            </div>




        </article>

    </div>
    <!--end row-->
</section>


<!--DeanStuSelCourse详细对话框-->
<div id="DeanStuSelCourseMessageModal" class="modal fade" id="ProviderMessageModal" tabindex="-1" role="dialog"
    aria-labelledby="DeanStuSelCourseMessageModalLabel" aria-hidden="true">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                ×</button>
            <h3>学生所修课程详细信息</h3>
        </div>

        <div class="modal-body">
            <input type='hidden' id='txtbID' name='txtbID' />
            <form class="smart-form" id="formDeanStuSelCourse" >
                <fieldset>
                    <section>
                        <label class="label">学生学号/姓名(请输入):</label>
                        <label class="input">
                            <input type='text' id='txtbSStuNo' name='txtbSStuNo' placeholder=''  class="typeahead" />
                        </label>
                    </section>
                    <section>
                        <label class="label">课程(请输入):</label>
                        <label class="input">
                            <input type='text' id='txtbSCouseCode' name='txtbSCouseCode' placeholder=''  />
                        </label>
                    </section>
                    <section>
                        <label class="label">教师(请输入):</label>
                        <label class="input">
                            <input type='text' id='txtbSTeacherCode' name='txtbSTeacherCode' placeholder=''  />
                        </label>
                    </section>
                    <section>
                        <label class="label">学年学期:</label>
                        <label class="input">
                            <input id='txtbSTermName' name='txtbSTermName' type='text' placeholder=' '  />
                        </label>
                    </section>
                </fieldset>
            </form>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">
                取消</button>
            <button id="btnSaveOrUpdateModel" class="btn btn-primary" aria-hidden="true" data-bind=" click: onDataAddingOrUpdate">
                确定</button>
        </div>
    </div>
    <!--end div content-->
</div>
<!--/详细DeanStuSelCourse对话框-->


<script type="text/javascript">

    var gdViewModel;

    var sex = function (i)
    {
        if (i == 0)
            return " ";
        if (i == 1)
            return "女";
        else
            return "男";
    }


    $(function () {
        

        $._messengerDefaults = {
            extraClasses: 'messenger-fixed messenger-theme-future messenger-on-bottom messenger-on-right'
        }; //默认提示位置;


        var options = {

            dialogId: "DeanStuSelCourseMessageModal", //添加对话框

            pageSize: 20, //分页大小
            hidId: $("#txtbID"),
            SaveUpdateBtn: $("#btnSaveOrUpdateModel"),
            frmElement: $("#formDeanStuSelCourse"),

            //节点数据
            NodeValue: ko.observable({

                Id: 0,
                SStuNo: '',
                SStuName: '',
                ISex: 0,
                ICourseId: 0,
                SCourseName: '',
                SCouseCode: '',
                ITeacherId: '',
                STeacherCode: '',
                STeacherName: '',
                IDeanOpenCourseId: '',
                STermName: '',


            }),


            //用户列表Grid头部列名称
            headers: [


 { displayText: 'ID', value: 'Id', width: 'auto' },
 { displayText: '学生学号', value: 'SStuNo', width: 'auto' },
 { displayText: '学生姓名', value: 'SStuName', width: 'auto' },
 { displayText: '性别', value: 'ISex', width: 'auto' },
 { displayText: '课程名', value: 'SCourseName', width: 'auto' },
 { displayText: '课程代码', value: 'SCouseCode', width: 'auto' },
 { displayText: '教师工号', value: 'STeacherCode', width: 'auto' },
 { displayText: '教师姓名', value: 'STeacherName', width: 'auto' },
 { displayText: ' 学年学期名', value: 'STermName', width: 'auto' }


            ],

            //默认的排序方式
            defaultOrderBy: "Id",
            //用户查询URL
            dataQueryUrlAccessor: function () {
                return "/api/DeanStuSelCourse/GetByPage";
            },

            //添加用户URL
            dataAddUrlAccessor: function () { return "/api/DeanStuSelCourse/Post"; },
            dataUpdateAccessor: function (key) {
                AddOrUpdate();
                return "/api/DeanStuSelCourse/Put/" + key;
            },
            dataNodeSelect: function (id) {
                return "/api/DeanStuSelCourse/get/" + id;
            },

            dataDeleteAccessor: function (data) {
                var userIDs = "";
                var check = $("input:checked");  //得到所有被选中的checkbox
                check.each(function (i) {        //循环拼装被选中项的值
                    userIDs = userIDs + ',' + $(this).val();
                });
                //清除多余的分割号
                userIDs = dropRsplit(userIDs, ",");
                if (userIDs != "") {
                    return appendQueryString("/api/DeanStuSelCourse/DeleteIds", { ids: userIDs });
                } else
                    return "";

            }
			, initEd: function () {
			    //gird初始化的后置事件 信息

			}
             , AddBefore: function () {
                 //向表单发送值
                 AddOrUpdate();
                 return true;
             }
             , showDlgBefore: function () {
                 
             }

            , changeEnd: function () {
            }
            , showDetailEnd: function (data) {
                $('#txtbSStuNo').val(data.SStuNo + ":" + data.SStuName + ":" + data.ISex);
                $('#txtbSTeacherCode').val(data.STeacherCode + ":" + data.STeacherName + ":" + data.ITeacherId);
                $("#txtbSCouseCode").val(data.SCouseCode + ":" + data.SCourseName + ':' + data.ICourseId);
                $('#txtbSTermName').val(data.IDeanOpenCourseId + ":" + data.STermName);
            }

        };

        gdViewModel = new gridViewModel(options);


        gdViewModel.init();
        ko.applyBindings(gdViewModel);

        options.frmElement.validate({
            rules: {
                txtbSStuNo: { required: true, maohao2: true },
                txtbSCouseCode: { required: true, maohao2: true },
                txtbSTeacherCode: { required: true, maohao2: true },
                txtbSTermName: { maohao1: true }
            },
            messages: {


                txtbSStuNo: { required: '请填写' },
                txtbSCouseCode: { required: '请填写' },
                txtbSTeacherCode: { required: '请填写' },
                txtbSTermName: { required: '请填写' }
            }
        });

        //学生下拉列表
        $('#txtbSStuNo').typeahead({
            source: function (query, process) {
                var sno = $('#txtbSrSStuNo');
                var url = "/Api/Students/GetAll"
                $.ajax({
                    type: "post",
                    url: url
                }).done(function (data) {
                    var arr = [];
                    for (i in data) {
                        arr.push(data[i].SNo + ":" + data[i].SName + ":" + data[i].ISex);
                    }
                    process(arr);
                })
            }
        });
        //教师下拉列表
        $('#txtbSTeacherCode').typeahead({
            source: function (query, process) {
                var sno = $('#txtbSTeacherCode');
                var url = "/Api/Teachers/GetAll";
                $.ajax({
                    type: "post",
                    url: url
                }).done(function (data) {
                    var arr = [];
                    for (i in data) {
                        arr.push(data[i].STeaNo + ":" + data[i].STeaName + ":" + data[i].Id);
                    }
                    process(arr);
                })
            }
        });

        //学期下拉列表
        $('#txtbSTermName').typeahead({
            source: function (query, process) {
                var sno = $('#txtbSTermName');
                var url = "/Api/DeanTerm/GetAll"
                $.ajax({
                    type: "post",
                    url: url
                }).done(function (data) {
                    var arr = [];
                    for (i in data) {
                        arr.push(data[i].Id + ":" + data[i].STermName);
                    }
                    process(arr);
                })
            }
        });

        //课程下拉列表
        $('#txtbSCouseCode').typeahead({
            source: function (query, process) {
                var sno = $('#txtbSCouseCode');
                var url = "/Api/DeanCourse/GetAll"
                $.ajax({
                    type: "post",
                    url: url
                }).done(function (data) {
                    var arr = [];
                    for (i in data) {
                        arr.push(data[i].SCourseCode + ":" + data[i].SCourseName + ':' + data[i].Id);
                    }
                    process(arr);
                })
            }
        });

        var AddOrUpdate = function () {
            //拆分学生信息
            var Stu = $('#txtbSStuNo').val().split(":");
            options.NodeValue().SStuNo = Stu[0]
            options.NodeValue().SStuName = Stu[1];
            options.NodeValue().ISex = Stu[2];
            //拆分教师信息
            var Tea = $('#txtbSTeacherCode').val().split(":");
            options.NodeValue().STeacherCode = Tea[0];
            options.NodeValue().STeacherName = Tea[1];
            options.NodeValue().ITeacherId = Tea[2];
            //拆分课程
            var course = $("#txtbSCouseCode").val().split(":");
            options.NodeValue().SCouseCode = course[0];
            options.NodeValue().SCourseName = course[1];
            options.NodeValue().ICourseId = course[2];
            //拆分学期
            var Term = $('#txtbSTermName').val().split(":");
            options.NodeValue().IDeanOpenCourseId = Term[0];
            options.NodeValue().STermName = Term[1];
        }
    });

</script>






<!--/end grid code-->

